package cn.easy.confirm;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 张澎_9970
 * @date 2021.12.15 下午 3:29 星期三
 * @desc:
 *  生产者 发消息 给交换机, 出错后, 回调函数
 */
@Component
public class MyReturnCallback implements RabbitTemplate.ReturnCallback {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    /**
     * 一旦出现错误, 调用该方法
     * @param message 消息本身
     * @param replyCode 响应状态码
     * @param replyText 错误的信息描述
     * @param exchange 交换机
     * @param routingKey routingKey
     */
    @Override
    public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        System.out.println("message: " + new String(message.getBody()));
        System.out.println("replyText: " + replyText);
        System.out.println("exchange: " + exchange);
        System.out.println("routingKey: " + routingKey);
    }
}